/**
  ******************************************************************************
  * Copyright(c) 2018-2023Vincent All rights reserved.
  * - Filename
  * - Author  Vincent
  * - Version V1.0.0
  * - Date    2018/11/5
  * - Brief
  * - FunctionList:
  ******************************************************************************
  * History:
  *
  *
  *
  ******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "can_interface.h"
#include "dbg.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

/* prama define discrible -----------------------------------------------------*/
// #define command "/sbin/ip link set can0 type can bitrate 125000" //将CAN0波特率设置为125000 bps
// #define up "ifconfig can0 up"                                    //打开CAN0
// #define down "ifconfig can0 down"                                //关闭CAN0
/* strcuct  discrible --------------------------------------------------------*/

/* prama  discrible ---------------------------------------------------------*/

/* private fucntion  declaration --------------------------------------------*/
void canrecive(int can_id, uint8_t *buf, int buf_len)
{
    int i;
    printf("ID: 0x%04X,LEN: %02d\t", can_id, buf_len);
    for (i = 0; i < buf_len; i++)
    {
        printf("%02X  ", *(buf + i));
    }
    printf("\r\n");
}
/*--------------------------------------------------------------------------
- @Name:
- @Discrible:
- @Param:
- @Return:
- @Others:
--------------------------------------------------------------------------
- @Recode    date       version         author             modify
-          ------------------------------------------------------------------
-          20190130      V1.0          VINCENT            Create
-
--------------------------------------------------------------------------*/
int main()
{
    int ret ;
    can_device_t vcu_can;
    can_obj_t send_obj;
    uint8_t i = 0;

    ret = can_init(&vcu_can, "can0", canrecive);
    if(ret < 0 )
    {
        printf(">> can device init error!\r\n");
        return 0;
    }
    can_open(&vcu_can);

    while (1)
    {
        sleep(2);
        send_obj.id = i++;
        strcpy(send_obj.data_buf, "HELLO");
        send_obj.data_len = strlen("HELLO");

        printf("send: ID: 0x%04X   len: %02d\r\n", send_obj.id, send_obj.data_len);
        can_transimit(&vcu_can, &send_obj, 1);
    }
    can_close(&vcu_can);
    return 0;
}
/************************ (.c) END OF FILE ************************************/